<?php

class LuminousGrammarPython extends LuminousGrammar
{
  public $operators = array('(?<![a-zA-Z0-9_])and(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])not(?![a-zA-Z0-9_])', 
    '(?<![a-zA-Z0-9_])i[ns](?![a-zA-Z0-9_])',    
    '(?<![a-zA-Z0-9_])or(?![a-zA-Z0-9_])',
    '\+', '\*', '-', '\/', '=', '&[gl]t;', '=','!', '%', '&amp;', '\|','~',
    '\^', '\[', '\]');
    
  public $keywords = array('del', 'for', 'raise', 'assert', 'elif', 'from', 
    'lambda', 'return', 'break', 'else', 'global', 'try', 'class', 'except', 
    'if', 'while','continue', 'exec', 'import', 'pass', 'yield', 'def', 
    'finally', 'print', 'as');
  
  // okay so these aren't really types but it makes it more colourful.
  public $types = array('False', 'True', 'None',
    'self',
    'int', 'float', 'long', 'complex',
    'str', 'unicode', 'list', 'tuple', 'buffer',
    'set', 'frozenset', 'dict',
    'memoryview',
    'Ellipsis',
  );
  
  public $functions = array('all', 'abs', 'any', 'basestring','bin',
    'callable', 'classmethod', 'cmp', 'compile',  'dir',
    'divmod', 'enumerate', 'eval', 'execfile', 'file', 'filter',
    'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash',
    'help', 'hex', 'id', 'input', 'isinstance', 'issubclass', 'iter',
    'len', 'locals', 'map', 'max', 'min', 'memoryview', 'next', 'object',
    'oct', 'open', 'ord', 'pow', 'print', 'property', 'range', 'raw_input',
    'reduce', 'reload', 'repr', 'reversed', 'round', 'setattr', 'slice',
    'sorted', 'staticmethod', 'sum', 'super', 'type', 'unichr', 'unicode',
    'vars', 'xrange', 'zip', '__import__'
    );
  public $oo_separators = array('\.');
  
  
  // hurray for languages with easy to find grammars
  // http://docs.python.org/reference/lexical_analysis.html#numeric-literals
  // also: EPIC.
  public $numeric_regex = '
  /(?<![[:alnum:]_<$])
  (
    #hex
    (?:0[xX][0-9A-Fa-f]+[lL]*)
    |
    # binary
    (?:0[bB][0-1]+)
    |
    #octal
    (?:0[oO0][0-7]+)
    |
    # regular number
    (?:
      (?>[0-9]+)
      (?: 
        # long identifier
        [lL]
        |
        # Or a fractional part, which may be imaginary
        (?:
          (?:\.?(?>[0-9]+)?        
            (?:(?:[eE][\+\-]?)?[0-9]+)?
          )[jJ]?
        )
      )?
    )
    |
    (
      # or only after the point, float x = .1;
      \.(?>[0-9]+)(?:(?:[eE][\+\-]?)?[0-9]+)?[jJ]?
    )
  )
  /x';
  
  
    
  public function __construct()
  {
    
    $this->SetInfoAuthor( 
    array('name'=>'Mark Watkinson', 'email'=>'markwatkinson@gmail.com',
          'website'=>'http://www.asgaard.co.uk'));
    $this->SetInfoLanguage('py');
    $this->SetInfoVersion('0.4.0');    
    
    $this->delimited_types = array(
      luminous_generic_shebang(),
      luminous_generic_comment("#", "\n"),
      luminous_generic_doc_comment("'''", "'''"),
      luminous_generic_doc_comment('"""', '"""'),
      
      new LuminousDelimiterRule(0, 'STRING', LUMINOUS_REGEX, 
      '/[ruRU]{0,2}\'/', '/\'/', 'luminous_type_callback_pystring'),
      
      new LuminousDelimiterRule(0, 'STRING', LUMINOUS_REGEX, 
      '/[ruRU]{0,2}"/', '/"/', 'luminous_type_callback_pystring')    
      );
      

    
    $this->SetSimpleTypeRules();
    $this->simple_types[] = luminous_generic_constant();
    
  }
}

